<?php if($order_info[0]['id']<1 ){?>
<div style="text-align: center">
    <div style="height: 5rem"></div>
    <h3>老版本的订单没有订单详情。</h3>
    <div>
        <a href='#' onclick='javascript:history.back(-1);'>返回上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <a href='/' >返回首页</a>
    </div>
</div>
<?php }else{ ?>
<div style='text-align: right'>
    <?php if($order['status']==1) { ?>
    <a href="/home/order/update?id=<?php echo $order_info[0]['order_id'];?>" onclick="return over();">订单子项消费全部完毕，关闭（完成）订单。</a>
    <?php }else{ ?>
    <a href='/home/order' >返回上一页</a>&nbsp;&nbsp;&nbsp;&nbsp;
    <?php } ?>
</div>

<div class="_cut"></div>
<div id='content' style='padding:5rem'>
    <?php foreach($order_info as $k=>$v){ ?>
    <div class="form-group row">
        商品名：<a target='_blank' href='/home/goods/detail?id=<?php echo $v['item_id'];?>&store_id=<?php echo $v['store_id'];?>'><b><?php if($v['item']['items']){ echo $v['item']['items'][$k]['name']; }else{ echo $v['item']['name'];}?></b></a>&nbsp;&nbsp;&nbsp;&nbsp;
        剩余：<b id='num_<?php echo $v['id'];?>' class='number'><?php echo $v['count'];?></b>&nbsp;次/个&nbsp;&nbsp;&nbsp;&nbsp;
        <?php if($v['count']>0 && $order['status']!=0){?>
        <input type='button' value='消费一次' onclick='sub(<?php echo $v['order_id'];?>,<?php echo $v['id'];?>);'>&nbsp;&nbsp;&nbsp;&nbsp;
        <?php }?>
        <?php if($order['status']==1){?>
        <input type='button' value='撤销一次' onclick='sub(<?php echo $v['order_id'];?>,<?php echo $v['id'];?>,1);'> 
        <?php }?>
    </div>
    <?php }?>
</div>
<script type='text/javascript'>
    function sub(order_id,id,bool){
        var url = "/home/order/";
        var number = $("#num_"+id).html();
        number = parseInt(number);
        if(bool != 1){
            url += "subtract?order_info_id="+id+'&order_id='+order_id;
            number = number-1;
        }else{
            url += "add?order_info_id="+id+'&order_id='+order_id;
            number = number+1;
        }
        $.ajax({
            url: url,
            async: true,
            success: function (data) {
                if (data == 'false') {
                    alert('操作失败，请稍候再试。');
                    return;
                }
                alert('操作成功');
                $("#num_"+id).html(number);
            }
        });
    }
    function over(){
        if(confirm('确定要执行此操作吗?')){
            var bool = true;
            $(".number").each(function(i){
                var num = $(this).html();
                num = parseInt(num);
                if(num>0){
                    bool = false;
                }
            });
            if(bool == false){
                alert("还有未完成的订单子项！！");
            }
            return bool;
        }
        return false;
    }
</script>
<?php }?>
